﻿Imports BUS
Imports DAO
Imports DTO
Imports DevComponents.DotNetBar

Public Class frmDanhSachSach
    Public Shared laymasach As String
    Public Shared laydongia As String

    Public Sub HienThiDanhSach()
        dgwDanhSachSach.DataSource = SachDAO.SelectSachAll()

    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub

    Private Sub frmDanhSachSach_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        colMaTheLoai.ValueMember = "MaTheLoai"
        colMaTheLoai.DisplayMember = "TenTheLoai"
        colMaTheLoai.DataSource = TheLoaiDAO.GetTheLoaiAll()
        HienThiDanhSach()
        cmbTheLoai.ValueMember = "MaTheLoai"
        cmbTheLoai.DisplayMember = "TenTheLoai"
        cmbTheLoai.DataSource = TheLoaiDAO.GetTheLoaiAll()
    End Sub

    Private Sub dgwDanhSachSach_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgwDanhSachSach.SelectionChanged
        If dgwDanhSachSach.SelectedRows.Count > 0 Then
            laymasach = dgwDanhSachSach.SelectedRows(0).Cells(0).Value.ToString()
            laydongia = dgwDanhSachSach.SelectedRows(0).Cells(2).Value.ToString()
        End If
    End Sub

    Private Sub btnChon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChon.Click
        frmPhieuNhapSach.MaSach = laymasach
        frmHoaDonBanSach.ms = laymasach
        frmHoaDonBanSach.dongia = laydongia
        Me.Close()
    End Sub

    Private Sub radTatCa_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radTatCa.CheckedChanged
        HienThiDanhSach()
    End Sub

    Private Sub radTenTacGia_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radTenTacGia.CheckedChanged
        Dim s As New SachDTO()
        s.TacGia = txtTimKiemSach.Text
        dgwDanhSachSach.DataSource = SachDAO.SelectSachLikeTacGia(s)
    End Sub

    Private Sub txtTimKiemSach_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTimKiemSach.TextChanged
        If radTenTacGia.Checked = True Then
            Dim s As New SachDTO()
            s.TacGia = txtTimKiemSach.Text
            dgwDanhSachSach.DataSource = SachDAO.SelectSachLikeTacGia(s)
        End If
        If radTatCa.Checked = True Then
            HienThiDanhSach()
        End If
        If radTenSach.Checked = True Then
            Dim s As New SachDTO()
            s.TenSach = txtTimKiemSach.Text
            dgwDanhSachSach.DataSource = SachDAO.SelectSachLikeName(s)
        End If
    End Sub

    Private Sub cmbTheLoai_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbTheLoai.SelectedIndexChanged
        Dim i As String = cmbTheLoai.SelectedValue.ToString()
        cmbTheLoai.DisplayMember = "TenTheLoai"

        HienThiDanhSach2(i)
    End Sub

    Public Sub HienThiDanhSach2(ByVal ma As String)
        Dim s As New SachDTO()
        cmbTheLoai.DataSource = TheLoaiDAO.GetTheLoaiAll()
        s.MaTheLoai = Integer.Parse(ma)
        dgwDanhSachSach.DataSource = SachDAO.SelectSachLikeMaTheLoai(s)
    End Sub
End Class